package com.example.fableoid;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.Menu;
import android.view.MotionEvent;

public class MainActivity extends Activity {
	private GestureDetector gestureDetector;
    @SuppressWarnings("deprecation")
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        gestureDetector = new GestureDetector(new SwipeGestureDetector());
    }
    
    public boolean onTouchEvent(MotionEvent event) {
        if (gestureDetector.onTouchEvent(event)) {
          return true;
        }
        return super.onTouchEvent(event);
      }
    
    private void onLeftSwipe() {
        Intent intent = new Intent(this,Selector.class);
        startActivity(intent);
      }

      private void onRightSwipe() {
        // Do something
      }
      
      private class SwipeGestureDetector extends SimpleOnGestureListener {

private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 200;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2,
                     float velocityX, float velocityY) {
  try {
    float diffAbs = Math.abs(e1.getY() - e2.getY());
    float diff = e1.getX() - e2.getX();

    if (diffAbs > SWIPE_MAX_OFF_PATH)
      return false;
    
    // Left swipe
    if (diff > SWIPE_MIN_DISTANCE
    && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
       MainActivity.this.onLeftSwipe();

    // Right swipe
    } else if (-diff > SWIPE_MIN_DISTANCE
    && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
      MainActivity.this.onRightSwipe();
    }
  } catch (Exception e) {
    Log.e("YourActivity", "Error on gestures");
  }
  return false;
}
} 

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    
}
